package logic

import (
	"context"
	"healthzy3/model/mysql"

	"healthzy3/healthzy3rpc/healthzy3rpc"
	"healthzy3/healthzy3rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *healthzy3rpc.ListRequest) (*healthzy3rpc.ListResponse, error) {
	// todo: add your logic here and delete this line

	var Healths []mysql.Health
	mysql.DB.Debug().Model(&Healths).Find(&Healths)

	var liststruct []*healthzy3rpc.ListStruct
	for _, Health := range Healths {
		list := &healthzy3rpc.ListStruct{
			Name:    Health.Name,
			Status:  Health.Status,
			IdCard:  Health.IdCard,
			Address: Health.Address,
			Cater:   Health.Cater,
			Type:    Health.Type,
			Doctor:  Health.Doctor,
			Price:   int64(Health.Price),
		}
		liststruct = append(liststruct, list)
	}

	return &healthzy3rpc.ListResponse{List: liststruct}, nil
}
